<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends CI_Controller
{
	public $data = array();

	public $layout = 'default';

	public $layout_dir = '';

	public function __construct()
	{
		parent::__construct();

		$this->load->driver('Cache');

		$this->load->library('Auth');
		$this->load->library('Template');

		if($this->layout)
		{
			$this->template->set_layout($this->layout, $this->layout_dir);
		}

		$this->data['base_url'] = base_url();
		$this->data['base_path'] = base_path();

		$this->data['styles'] = array(
			$this->data['base_url'] . 'assets/css/reset.css',
			$this->data['base_url'] . 'assets/css/960.css',
			$this->data['base_url'] . 'assets/css/text.css',
		);

		$this->data['scripts'] = array(
			'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js',
			//$this->data['base_url'] . 'assets/js/jquery-1.4.4.min.js',
		);

		$this->data['keywords'] = '';
		$this->data['description'] = '';

		$this->data['user']['is_logged'] = $this->auth->is_logged_in();
		$this->data['user']['user_id'] 	 = $this->data['user']['is_logged'] ? $this->auth->get_user_id(): 0;
		$this->data['user']['user_name'] = $this->auth->get_username() ? $this->auth->get_username() : "Guest";
		$this->data['user']['user_role'] = $this->auth->get_role_name();
	}

	public function add_js($js)
	{
		if(!is_array($js))
		{
			$this->data['scripts'][] = $js;
		}
		else
		{
			$this->data['scripts'] = array_merge($this->data['scripts'], $js);
		}
	}

	public function add_css($css)
	{
		if(!is_array($css))
		{
			$this->data['styles'][] = $css;
		}
		else
		{
			$this->data['styles'] = array_merge($this->data['styles'], $css);
		}
	}
}

class Admin_Controller extends MY_Controller
{
	public $layout = 'backend';

	public function __construct()
	{
		parent::__construct();

		
		$this->load->library('Pagination');
		$this->load->library('Form_validation');

		$this->data['scripts'][] = 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js';
		$this->data['scripts'][] = $this->data['base_url'] . 'assets/js/jquery.pngFix.js';
		$this->data['scripts'][] = $this->data['base_url'] . 'assets/js/superfish.js';
		$this->data['scripts'][] = $this->data['base_url'] . 'assets/backend/js/common.js';
		$this->data['styles'][] = $this->data['base_url'] . 'assets/css/black/ui.css';
		$this->data['styles'][] = $this->data['base_url'] . 'assets/backend/css/styles.css';

		$this->template->set_partial('menu', 'backend/elements/menu');
		$this->template->set_partial('sub_menu', 'backend/elements/sub_menu');
		
		$this->template->set_breadcrumb('Quản lý', 'backend');
	}
}

// End MY_Controller